package com.firend.mapper;

import com.order.hit.crossover.platform.common.bean.Friend;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Lei
 * @version 0.1
 * @date 2020/9/8
 */

public interface FriendMapper {

    @Select("SELECT * FROM friend")
    @Results({
            @Result(property = "userId", column = "userId"),
            @Result(property = "friendId", column = "friendId"),
            @Result(property = "friendState", column = "friendState")
    })
    public List<Friend> getAllfrienfs();

    @Select("SELECT * FROM friend WHERE userId=#{userId} and friendId=#{friendId}")
    @Results({
            @Result(property = "userId", column = "userId"),
            @Result(property = "friendId", column = "friendId"),
            @Result(property = "friendState", column = "friendState")
    })
    public Friend getFriend(@Param("userId") int userId, @Param("friendId")int friendId);

    @Select("SELECT * FROM friend WHERE userId=#{userId}")
    @Results({
            @Result(property = "userId", column = "userId"),
            @Result(property = "friendId", column = "friendId"),
            @Result(property = "friendState", column = "friendState")
    })
    public List<Friend> getUserFriend(int userId);

    @Select("SELECT * FROM friend WHERE userId=#{userId} and friendState=#{state}")
    @Results({
            @Result(property = "userId", column = "userId"),
            @Result(property = "friendId", column = "friendId"),
            @Result(property = "friendState", column = "friendState")
    })
    public List<Friend> getUserFriendByState(@Param("userId") int userId, @Param("state") String state);


    @Select("SELECT * FROM friend WHERE friendId=#{firendId} and friendState=#{state}")
    @Results({
            @Result(property = "userId", column = "userId"),
            @Result(property = "friendId", column = "friendId"),
            @Result(property = "friendState", column = "friendState")
    })
    public List<Friend> getUserApplyByState(@Param("firendId") int firendId, @Param("state") String state);

    @Insert("Insert into friend (userId, friendId, friendState) VALUES (#{userId}, #{friendId}, #{friendState})")
    @Results({
            @Result(property = "userId", column = "userId"),
            @Result(property = "friendId", column = "friendId"),
            @Result(property = "friendState", column = "friendState")
    })
    public void addfriend(Friend friend);

    @Delete("delete from friend where userId = #{userId} and friendId=#{friendId}")
    public void deletefriend(Friend friend);

    @Update("update friend set friendState=#{friendState} where userId = #{userId} and friendId=#{friendId}")
    public void changeState(Friend friend);
}
